package com.itheima.web;

import com.itheima.domain.Student;
import com.itheima.servlet.StudentServlet;
import com.itheima.servlet.StudentServletImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/ListServlet")
public class ListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.调用service查询所有学生
        StudentServlet studentService = new StudentServletImpl();
        List<Student> all = studentService.findAll();

        //2.将学生存入request域
        request.setAttribute("students",all);
        //3.转发到list.jsp
        request.getRequestDispatcher("/list.jsp").forward(request,response);
//        request.getSession().setAttribute("students",all);
//        response.sendRedirect("list.jsp");
    }
}
